home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / jmod311.zip / TEST.C < prev    next >
Text File  |  1992-02-02  |  11KB  |  298 lines

  1. /****************************************************************************/
  2. /*     These routines test the data-compression and expansion routines      */
  3. /*     To alter:                                                            */
  4. /*     MAKE TEST                                                            */
  5. /*     ( use the MAKE file )                                                */
  6. /*                                                                          */
  7. /*     When compiling, you will get 3 warning messages about unused         */
  8. /*     parameters. This is because of the dummy screen() routine which      */
  9. /*     does nothing except keep the linker happy.                           */
  10. /*                                                                          */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*     When executed, this program uses the timer-tick for data and tests   */
  14. /*     compression/expansion for all data lengths used.                     */
  15. /*     It takes about 84 hours to execute.  It aborts on the first error.   */
  16. /*                                                                          */
  17. /*     Since one might like to stop it to use their computer, I added       */
  18. /*     routines so it may be restarted with the last buffer size.           */
  19. /*                                                                          */
  20. /*     This routine thoroughly tests both the file I/O and the compression  */
  21. /*     expansion, CRC routines to verify that they will NOT corrupt any     */
  22. /*     data. These tests are exhaustive. They were used to find the         */
  23. /*     MicroSoft stream-I/O bug and are the reason I changed to the         */
  24. /*     Unix-type "handle" file routines.                                    */
  25. /*                                                                          */
  26. /*                                                                          */
  27. /****************************************************************************/
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>                     /* Used for _free()                 */
  31. #include <string.h>
  32. #if defined (TURBOC)
  33.     #include <alloc.h>
  34. #else
  35.     #include <malloc.h>
  36. #endif
  37. #include <time.h>
  38. #define SCREEN
  39. #include "jmodem.h"
  40.  
  41. byte far *tick = (byte far *) 0x46C;
  42. SYS syst;
  43. short main (void);
  44. char input[64];
  45. byte *in_buf;
  46. byte *out_buf;
  47. byte *cmp_buf;
  48. byte *sav_ptr;
  49. void show_hex(word, byte *);
  50. char file_name[]="JMODEM.$$$";
  51. word status;
  52. short handle;
  53.  
  54. short main()
  55. {
  56.     word i,j,k,l;
  57.     short flag = 1;
  58.     short max = DAT_MAX;
  59.     l =  DAT_MAX;
  60.     printf("\nBuffer size? (%d) ",DAT_MAX);
  61.     gets(input);
  62.     sscanf(input," %d",&l);
  63.     max = l;
  64.  
  65.     in_buf  = (byte *) malloc(l);                      /* Allocate buffer */
  66.     if (!in_buf)                                       /* If an error     */
  67.     {
  68.         printf("\nMemory error!");
  69.         return 1;
  70.     }
  71.     out_buf = (byte *) malloc(l);                       /* Allocate buffer */
  72.     if (!out_buf)                                       /* If an error     */
  73.     {
  74.         printf("\nMemory error!");
  75.         return 1;
  76.     }
  77.  
  78.     printf("Will write %d records.",l);
  79.     input[0] = 0x00;
  80.     while (input[0] != 'C' && input[0] != 'F')
  81.     {
  82.         printf("\nTest CRC and compressor or File I/O? (C/F) ");
  83.         gets(input);
  84.         input[0] = input[0] & (char)95;
  85.     }
  86.     switch (input[0])
  87.     {
  88.         case 'F':
  89.         {
  90.         printf("\nWant to check CRC / comp. after the file test? (Y/N) ");
  91.             gets(input);
  92.             if ( (input[0] & 95) == 'Y')
  93.                 flag = 0;
  94.             sav_ptr = out_buf;
  95.             for (i=0; i<l; i++)
  96.                 *out_buf++ = (byte) i;
  97.             out_buf = sav_ptr;
  98.             while (l)
  99.             {
  100.                 remove ("JMODEM.OLD");
  101.                 printf("\nOpening file %s for write.",file_name);
  102.                 status = file_io(CREATE, &handle, 
  103.                                          file_name, (byte *) 0x0000) ;
  104.                 if (status)
  105.                 {
  106.                     printf("\nOpen failed~!");
  107.                     return(1);
  108.                 }
  109.                 printf("\nWriting file %s",file_name);
  110.                 for (i=0; i<100; i++)
  111.                 {
  112.                     printf("\nRecord %d,",i);
  113.                     status = file_io( WRITE ,            /* Function        */
  114.                                  &handle,                /* File handle     */
  115.                                  out_buf,                /* Where data is   */
  116.                                  l );                    /* Amount to write */
  117.                     if (status != l)
  118.                     {
  119.                         printf(" only wrote %d bytes!",status);
  120.                         return 1;
  121.                     }
  122.                     printf(" %d bytes okay.",status);
  123.                  }
  124.                  printf("\nClosing file");
  125.                  file_io(CLOSE,                          /* Function        */
  126.                        &handle,                          /* Open handle     */
  127.                        file_name,                        /* Name not used   */
  128.                        (byte *) 0x0000);                 /* Buffer not used */
  129.  
  130.                 printf("\nOpening file %s for read.",file_name);
  131.                 status = file_io(OPEN_READ, &handle,
  132.                                             file_name,
  133.                                             (byte *) 0x0000);
  134.                 if (status)
  135.                 {
  136.                     printf("\nOpen failed~!");
  137.                     return(1);
  138.                 }
  139.  
  140.                 printf("\nReading file %s",file_name);
  141.                 for (i=0; i<100; i++)
  142.                 {
  143.                     printf("\nRecord %d,",i);
  144.                     status = file_io( READ ,             /* Function        */
  145.                                  &handle,                /* File handle     */
  146.                                  in_buf,                 /* Where data is   */
  147.                                  l );                    /* Amount to write */
  148.                     if (status != l)
  149.                     {
  150.                         printf(" only read %d bytes!",status);
  151.                         return 1;
  152.                     }
  153.                     printf(" %d bytes okay,",status);
  154.  
  155.                     printf(" comparing,");
  156.                     k = memicmp (out_buf, in_buf,l);
  157.                     if (k)
  158.                     {
  159.                         printf(" did not compare!");
  160.                         return(1);
  161.                     }
  162.                     printf(" okay.");
  163.  
  164.                  }
  165.                  printf("\nClosing file");
  166.                  file_io(CLOSE,                          /* Function        */
  167.                        &handle,                          /* Open handle     */
  168.                    file_name,                            /* Name not used   */
  169.                    (byte *) 0x0000);                     /* Buffer not used */
  170.             l--;
  171.             }
  172.             remove ("JMODEM.OLD");
  173.             remove ("JMODEM.$$$");
  174.             if (flag)
  175.                 return(0);
  176.         }
  177.         case 'C':
  178.         {
  179.             l = max;
  180.             cmp_buf = (byte *) malloc(DAT_LEN);          /* Allocate buffer */
  181.             if (!cmp_buf)                                /* In an error     */
  182.             {
  183.                 printf("\nMemory error!");
  184.                 return 1;
  185.             }
  186.             printf("\nFilling the input buffer with consecutive bytes.");
  187.             sav_ptr = in_buf;                           /* Save            */
  188.             for (i=0; i< l; i++)
  189.                 *in_buf++ = (byte) i;                   /* Fill the buffer */
  190.  
  191.             in_buf = sav_ptr;
  192.             printf("\nAttempting to compress.");
  193.             j = encode ( l,in_buf, cmp_buf);            /* Compress the data*/
  194.